<?php 
	include('class_nguoiban.php');
?>

<script type="text/javascript">
function XuLyLikeGianHang(MaNguoiBan, MaNguoiMua)
{
	var url ="index.php?com=nguoiban&fun=detail&MaNguoiBan="+MaNguoiBan;
				url += "&mnb="+MaNguoiBan;
				url += "&mnm="+MaNguoiMua;
				url += "&type=1";
				
	document.location.href = url;
}

function XuLyDangKyNhanThongTinGianHang(MaNguoiBan, MaNguoiMua)
{
	var url ="index.php?com=nguoiban&fun=detail&MaNguoiBan="+MaNguoiBan;
				url += "&mnb="+MaNguoiBan;
				url += "&mnm="+MaNguoiMua;
				url += "&type=2";
				
	document.location.href = url;
}
</script>
<?php
	$mnb = 0;
	$mnm = 0;
	$type = 0;
	if(isset($_REQUEST['type']))
		$type = $_REQUEST['type'];
	if(isset($_REQUEST['mnb']))
		$mnb = $_REQUEST['mnb'];
	if(isset($_REQUEST['mnm']))
		$mnm = $_REQUEST['mnm'];
	if($type == 1)
	{
		LikeGianHang($mnb, $mnm);
		echo "Đã Like gian hàng!";
	}
	
	if($type == 2)
	{
		DangKyNhanThongTinGianHang($mnb, $mnm);
		echo "Đăng ký nhận thông tin gian hàng thành công!";
	}	
	
	function LikeGianHang($manguoiban, $manguoimua)
	{
		$tb = new class_nguoiban();
		$tb->XuLyLikeGianHang($manguoiban, $manguoimua);
	}
	
	function DangKyNhanThongTinGianHang($manguoiban, $manguoimua)
	{
		$tb = new class_nguoiban();
		$tb->XuLyDangKyNhanThongTinGianHang($manguoiban, $manguoimua);
	}
?>


<div class="art-post">
                                <div class="art-post-tl"></div>
                                <div class="art-post-tr"></div>
                                <div class="art-post-bl"></div>
                                <div class="art-post-br"></div>
                                <div class="art-post-tc"></div>
                                <div class="art-post-bc"></div>
                                <div class="art-post-cl"></div>
                                <div class="art-post-cr"></div>
                                <div class="art-post-cc"></div>
                                <div class="art-post-body">
                            <div >
                                            <div class="art-postmetadataheader">
                                                <h2 class="art-postheader">
                                                    <img src="images/postheadericon.png" width="32" height="32" alt="postheadericon" />
                                                    Gian Hàng Người Bán
                                                </h2>
                                            </div>
                                            <div class="art-postcontent"><br/>
                                                <!-- article-content -->

<?php
	$nb = new class_nguoiban();
	
//	$countNB = $nb->CountListNguoiBanViewNhieuNhat();
//	$countSP = $sp->CountListSanPhamViewNhieuNhat();
//	
//	$pager = new Pager();
//	$limit = 3;
//		
//	$start = $pager->findStart($limit);
//	$pages = $pager->findPages($count,$limit);
//	
//	if ($_GET['loai'] == 1)
//	{
//		$ls = 'com=trangchu&fun=trangchu&loai=1';
//		$listpagingNB = '' ;
//		if($countNB > $limit)
//		{
//			$listpagingNB = $pager->pageList($_GET['page'], $pages,$ls);
//		}
	
	// thông tin người bán ///////////////////////////////////////////////////////////////////////////////////////
		$tb = $nb->ChiTietNguoiBan($_GET['MaNguoiBan']);
		$str = '';
		if (count($tb) == 0)
		{
			echo '<br/><div align="center"><b>Không có gian hàng nào.</b></div>';
		}
		$str .= '<h1>Thông tin gian hàng</h1>';
		
		foreach ($tb as $row)
		{
			$str .= '<table align="center" width="710" border="0">
	  <tr>
		<td width="130" rowspan="6"><img src="../images/nguoiban/'.$row['HinhAnh'].'" width="120px" height="160px" /></td>
		<td align="left" colspan="2" style="font-weight:bold; font-size:16px">';
		if ($row['Username'] == NULL)
		{
			$row['Username'] = 'Đã xóa';
		}
		$manguoimua = $_SESSION["MaUser"];
		$manguoiban = $row['MaSo'];
		$str .= '<a href="index.php?com=nguoiban&fun=detail&MaNguoiBan='.$row['MaSo'].'">'.$row['Username'].'</a></td>
		<input type="button" name="LikeGianHang" value="Like" onclick="XuLyLikeGianHang('.$manguoiban.', '.$manguoimua.')">
		<input type="button" name="DangKyNhanThongTinGianHang" value="Đăng ký nhận tin" onclick="XuLyDangKyNhanThongTinGianHang('.$manguoiban.', '.$manguoimua.')">
	  </tr>
	  <tr>
		<td width="290">Email: '.$row['Email'].'</td>
		<td>Họ tên: '.$row['HoTen'].'</td>
	  </tr>
	  <tr>
		<td>Địa chỉ: '.$row['DiaChi'].'</td>
		<td>Điện thoại: '.$row['DienThoai'].' </td>
	  </tr>
	  <tr>
		<td>Giới tính: ';
		$GioiTinh = '';
		if ($row['GioiTinh'] == 1)
		{
			$GioiTinh = 'Nam';
		}
		else
		{
			$GioiTinh = 'Nữ';
		}
		$str .= $GioiTinh.'</td>
		<td>Ngày sinh: ';
		
		$ThoiGian = $row['NgaySinh'];
		$nam = substr($ThoiGian,0,4);
		$thang = substr($ThoiGian,5,2);
		$ngay = substr($ThoiGian,8,2);
		$gio = substr($ThoiGian,11,2);
		$phut = substr($ThoiGian,14,2);
		$giay = substr($ThoiGian,17,2);
		$ThoiGian = $ngay.'/'.$thang.'/'.$nam;
		
		$str .= $ThoiGian.'</td>
	  </tr>
	  <tr>';
	  
		$ThoiGian = $row['NgayDangKy'];
		$nam = substr($ThoiGian,0,4);
		$thang = substr($ThoiGian,5,2);
		$ngay = substr($ThoiGian,8,2);
		$gio = substr($ThoiGian,11,2);
		$phut = substr($ThoiGian,14,2);
		$giay = substr($ThoiGian,17,2);
		$ThoiGian = $gio.':'.$phut.':'.$giay.' '.$ngay.'/'.$thang.'/'.$nam;
	  
		$str .= '<td>Ngày đăng ký: '.$ThoiGian.'</td>
		<td>Like: '.$row['TongSoLike'].'</td>
	  </tr>';
	  
	  
	  $str .= '<tr>
				<td>Lượt xem: '.$row['PageView'].'</td>
				<td>Trạng thái: ';
				
				$TrangThai = $row['TrangThaiTaiKhoan'];
				switch ($TrangThai)
				{
					case 0:
						$TenTrangThai = 'Chưa kích hoạt';
						break;
					case 1:
						$TenTrangThai = 'Bình thường';
						break;
					case 2:
						$TenTrangThai = 'Cảnh cáo';
						break;
					case 3:
						$TenTrangThai = 'Khóa';
						break;
				}
				
				$str .= $TenTrangThai.'</td>
			</tr>';
	  
	  
	  $str .= '<tr>
		<td colspan="3">
		<hr align="center" style="border:thin dotted" color="#00CC00"  />
		</td>
	 </tr>
	</table>';
		
		}
		echo $str;


	// sự kiện /////////////////////////////////////////////////////////////////////////////////////////////
		echo '<div id="SuKienByMaNguoiBan">';
		include('detail_sukien.php');
		echo '</div>';
	// sản phẩm ///////////////////////////////////////////////////////////////////////////////////////
		echo '<div id="SanPhamByMaNguoiBan">';
		include('detail_sanpham.php');
		echo '</div>';

	
?>



<!-- /article-content -->
                                            </div>
                                            <div class="cleared"></div>
                            </div>
                            
                            		<div class="cleared"></div>
                                </div>
                            </div>